package com.caigou.comm.base.network.interceptors

import com.caigou.comm.base.utils.Logger
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

/**
 * @author #Suyghur.
 * Created on 2021/09/13
 */
class LoggingInterceptor : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val t1 = System.nanoTime()
        Logger.d("Sending request: ${request.url}")
        val response = chain.proceed(request)
        val t2 = System.nanoTime()
        Logger.d("Received response for ${response.request.url} in ${(t2 - t1) / 1e6}ms")
        return response
    }
}